package com.thrblock.needle.bean;

import geivcore.UesContext;
import geivcore.Uesi;
import geivcore.enginedata.obj.Obj;

import com.thrblock.commoncwd.Individual;
import com.thrblock.util.UMath;

public class Needle implements Individual{
	static Uesi ues = UesContext.getCurrentContext();
	public static final float rad = 180f;
	static final float cx = ues.getScreenWidth() / 2;
	static final float cy = ues.getScreenHeight() / 2;
	static final String SMALL_HJ = ues.preInitTexture(Needle.class.getResourceAsStream("SMALLHJ.png"));
	
	float[] revertRes = new float[2];
	Obj needle;
	Obj line;
	public Needle() {
		line = ues.creatObj(Uesi.GameObjIndex);
		line.addGLLine("FFFF00", 0f,0f,cx,cy);
		needle = ues.creatObj(Uesi.GameObjIndex);
		needle.addGLImage(SMALL_HJ);
		needle.setCentralX(cx);
		needle.setCentralY(cy + rad + 100f);
	}
	@Override
	public boolean isAvalible() {
		return !needle.isPrintable();
	}
	@Override
	public void doStp(int clock) {
		
	}
	@Override
	public void finish(int src) {
		needle.hide();
		line.hide();
	}
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void getUse(Object[] ARGS, float... FARGS) {
		needle.setCentralX(cx);
		needle.setCentralY(cy + rad);
		
		line.setDxs(cx, 0);
		line.setDys(cy, 0);
		
		needle.show();
		line.show();
	}
	
	public void setAngleSpd(float angleSpd) {
		UMath.revolve(needle.getCentralX(),needle.getCentralY(), cx, cy, UMath.getTheta(angleSpd), revertRes);
		needle.setCentralX(revertRes[0]);
		needle.setCentralY(revertRes[1]);
		
		line.setDxs(revertRes[0], 0);
		line.setDys(revertRes[1], 0);
		
	}
	
	public boolean isCollide(Needle another) {
		return needle.PolygonCollide(another.needle);
	}
}
